BASS_Init

Initializes the BASS digital output system.

BOOL WINAPI BASS_Init(
    int device,
    DWORD freq,
    DWORD flags,
    HWND win
);

Parameters
deviceThe device to use... 0 = first, -1 = default, -2 = no sound. BASS_GetDeviceDescription can be used to get the total number of devices.
freqOutput sample rate.
flagsAny combination of these flags.
BASS_DEVICE_8BITSUse 8 bit resolution, else 16 bit.
BASS_DEVICE_MONOUse mono, else stereo.
BASS_DEVICE_3DEnable 3D functionality. If this flag is not specified, then the 3D flags (BASS_SAMPLE_3D and BASS_MUSIC_3D) are ignored when loading/creating a sample/stream/music.
winThe application's main window. If you're using the console, then you should use the handle returned by the GetForegroundWindow function.

Return value
If BASS was successfully initialized then TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_ALREADYBASS has already been initialized. You must call BASS_Free before calling BASS_Init again.
BASS_ERROR_DEVICEThe device number specified is invalid.
BASS_ERROR_DRIVERThere is no available device driver.
BASS_ERROR_FORMATThe specified format is not supported by the device. Try changing the freq and flags parameters.
BASS_ERROR_MEMThere is insufficent memory.
BASS_ERROR_NO3DThe device has no 3D support.
BASS_ERROR_UNKNOWNSome other mystery problem!

Remarks
This function must be successfully called before calling any other BASS functions, except BASS_ErrorGetCode, BASS_GetDeviceDescription, BASS_GetGlobalVolumes, BASS_GetVersion, BASS_SetBufferLength, BASS_SetGlobalVolumes, and the CD functions.

The no sound device allows loading and "playing" of MOD musics only, all sample/stream functions and most other functions fail. This is so that you can still use the MOD musics as synchronizers when there is no soundcard present. When using the no sound device, you should still set the other parameters as you would do normally.

It is advisable to have a "lower quality" option (eg. 22050hz instead of 44100hz) in your software, for users with slower computers.

Example
To initialize BASS, falling back to no sound if no device is available.

// try initializing the default device, at 44100hz stereo 16 bits
if (!BASS_Init(-1,44100,0,hwnd)) {
    // couldn't initialize device, so use no sound
    BASS_Init(-2,44100,0,hwnd)
}

See also
BASS_CDInit, BASS_Free, BASS_MusicLoad, BASS_Start, BASS_SampleLoad, BASS_SampleCreate, BASS_StreamCreate, BASS_StreamCreateFile